package com.tom.happy.mrs.chicken;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

public class LayEggsFragment extends BaseFragment implements View.OnTouchListener {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mLayoutResID = com.tom.happy.mrs.chicken.R.layout.fragment_lay_eggs;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        mLayoutView.findViewById(com.tom.happy.mrs.chicken.R.id.background).setOnTouchListener(this);
        return mLayoutView;
    }

    @Override
    public void onMotherAnimEnd() {
        mMother.setBackgroundResource(com.tom.happy.mrs.chicken.R.drawable.y_chicken_anim);
        ((AnimationDrawable) mMother.getBackground()).start();
        mHandler.removeMessages(MSG_MOTHER_CRY);
        mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_MOTHER_CRY), 2400);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            Message msg = mHandler.obtainMessage(MSG_MOVE_TO_POS);
            msg.arg1 = (int) event.getRawX() - mMotherWidth / 2;
            msg.arg2 = (int) event.getRawY() - mMotherWidth / 2;
            mHandler.sendMessage(msg);
        }
        return false;
    }
}
